import React from "react";
import { withRouter } from "react-router-dom";
import { pageIndex, pages } from "../../common/routerConfig";
import styles from "./index.module.scss";
import { loginAuth } from "../../common/auth";

// 结果显示页面
const Index = (props) => {
  const { history } = props;
  const query = props.location.query;
  let result;
  if (query) {
    result = query.result;
  } else {
    alert("还没有完成题目呢");
    history.go(-1);
  }

  const handleExit = () => {
    loginAuth.doLogout();
    history.push(pages[pageIndex.login].path);
  };

  const handleToHome = () => {
    history.push(pages[pageIndex.home].path);
  };

  return (
    <div className={styles.container}>
      <div className={styles.header}>🙃result🙂</div>
      <div className={styles.result}>{result}</div>
      <div className={styles.action}>
        <div className={styles.btn} onClick={handleExit}>
          退出登录
        </div>
      </div>
      <div className={styles.action}>
        <div className={styles.btn} onClick={handleToHome}>
          返回home
        </div>
      </div>
    </div>
  );
};

export default withRouter(Index);
